package simulator.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;

import simulator.Scenario;

/**
 * Swing component responsible for rendering the simulation header, including
 * system title, scenario description, and current clock cycle (step).
 * 
 * @author Kyle Loomis
 * 
 */
public class ScenarioHeader extends JComponent implements SimulationListener
{
   private static final long serialVersionUID = 1L;
   private static final Color defaultColor = new Color(100, 100, 100);
   private SimulationController controller = null;

   /**
    * Default constructor.
    * 
    * @param controller
    *           the simulation controller.
    */
   public ScenarioHeader(SimulationController controller)
   {
      this.controller = controller;
      this.controller.addSimulationListener(this);
   }

   public Dimension getPreferredSize()
   {
      return new Dimension(300, 70);
   }

   public void paintComponent(Graphics g)
   {
      super.paintComponent(g);

      Graphics2D area = (Graphics2D) g;
      area.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
      area.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      Font font = new Font("Arial", Font.BOLD, 24);
      area.setFont(font);
      area.setColor(defaultColor);

      area.drawString("OS Simulator", 10, 30);

      Font font2 = new Font("Arial", Font.PLAIN, 12);
      area.setFont(font2);

      String description = "";

      Scenario scenario = controller.getScenario();

      if (scenario != null)
      {
         description = scenario.getDescription();

         if (description == null)
         {
            description = "";
         }
         else
         {
            description = description.toUpperCase();
         }
      }

      area.drawString(description, 10, 45);
   }

   public void onScenarioChanged()
   {
      repaint();
   }

   public void onScenarioStart()
   {

   }

   public void onScenarioStop()
   {

   }
}
